﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Midi;
using AutomaTones.Model.Automaton_Model;
using Microsoft.Pex.Framework;

namespace AutomaTones.Model.MIDI.Mappers
{
    [PexClass]
    partial class MozartTranslator : IMapper
    {
        private readonly List<NoteOut> _notes = new List<NoteOut>();
        bool switcher=false;
        int noteTranslator=12;

        [PexMethod]
        public List<NoteOut> Translate(State[,] grid) {
            Random random = new Random();
            _notes.Clear();
            if (switcher) {
                noteTranslator *= -1;
            }
            else {
                noteTranslator *= -1;
            }
            for (int x = 0; x < grid.GetLength(0);x++)
                for (int y = 0; y < grid.GetLength(1); y++)
                    if (grid[x, y].CurrentState > 0) {
                        if (grid[x, y].CurrentState == 1) {
                            _notes.Add(new NoteOut(Pitch.C1+noteTranslator, random.Next(128)));
                            break;
                        }
                        if (grid[x, y].CurrentState == 2)
                        {
                            _notes.Add(new NoteOut(Pitch.A2 - noteTranslator, random.Next(128)));
                            break;
                        }
                        if (grid[x, y].CurrentState == 3) {
                            _notes.Add(new NoteOut(Pitch.E0 + noteTranslator, random.Next(128)));
                            break;
                        }
                        if (grid[x, y].CurrentState == 4)
                        {
                            _notes.Add(new NoteOut(Pitch.F0 - noteTranslator, random.Next(128)));
                            break;
                        }
                        if (grid[x, y].CurrentState == 5) {
                            _notes.Add(new NoteOut(Pitch.D0 + noteTranslator, random.Next(128)));
                            break;
                        }
                    }
            switcher = !switcher;
            return _notes;
        }
    }
}
